package com.xing.binbackend.pattern.adapter24.operation;

import cn.hutool.json.JSONObject;

public class AliyunMonitorAdapter implements CloudMonitor {
    private final AliyunSDK aliyunSDK = new AliyunSDK();

    @Override
    public MetricData getCpuUsage(String instanceId) {
        JSONObject data = aliyunSDK.queryMetricData("cpu_usage", instanceId);
        return new MetricData((double) data.get("value"), (long) data.get("timestamp"));
    }

    @Override
    public MetricData getMemoryUsage(String instanceId) {
        return null;
    }

    @Override
    public void setAlert(String metricName, double threshold) {
        aliyunSDK.createAlarmRule(metricName + "_Rule", metricName, "Average>" + threshold);
    }

    @Override
    public String getVendorType() {
        return getClass().getSimpleName();
    }
    // 其他方法类似...
}
